package com.lianzhihui.romeex.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.lianzhihui.romeex.utils.tools.SavePhoto;

/**
 * 图片转换工具
 *
 * @author zll
 */
public class ImagesUtil {

    //创建二维码的方法
    public static void createQrCodeImg300(String qrCodeString, ImageView ivQrCode) {
        if (TextUtils.isEmpty(qrCodeString) || ivQrCode == null) {
            return;
        }
        Bitmap bitmap = ZXingUtils.createQRImage(qrCodeString, 300, 300);
        Drawable drawable = new BitmapDrawable(bitmap);
        ivQrCode.setBackground(drawable);

    }

    //创建二维码的方法
    public static void createQrCodeImg(String qrCodeString, ImageView ivQrCode, int widthAndHeight) {
        if (TextUtils.isEmpty(qrCodeString) || ivQrCode == null) {
            return;
        }
        Bitmap bitmap = ZXingUtils.createQRImage(qrCodeString, widthAndHeight, widthAndHeight);
        Drawable drawable = new BitmapDrawable(bitmap);
        ivQrCode.setBackground(drawable);
    }

    public static void saveQrCode(Context mContext, View view) {
        if (view == null || mContext == null) {
            return;
        }
        SavePhoto savePhoto = new SavePhoto(mContext);
        savePhoto.SaveBitmapFromView(view);
    }

}
